package org.deltaset.secured.user;

import javax.inject.Inject;
import org.springframework.stereotype.Repository;

/**
 *
 * @author dmakariev
 */
@Repository
public class PreferencesRepository {

    private final UserContextStorage userContextStorage;

    @Inject
    public PreferencesRepository(UserContextStorage userContextStorage) {
        this.userContextStorage = userContextStorage;
    }

    public UserContext loadUserContext() {
        return null == userContextStorage.getUserContext() ? UserContext.newUserContext() : userContextStorage.getUserContext();
    }

    public void saveUserContext(UserContext uc) {
        if (null == uc) {
            throw new IllegalArgumentException("UserContext cannot be Null !");
        }
        userContextStorage.setUserContext(uc);
    }
}
